#coding: utf-8
from django.shortcuts import render_to_response
from jobs.models import Template


def index(request):
    item = request.GET.get('V', 0)
    try:
        item = int(item)
    except Exception, e:
        print(e)
        pass

    fck = {'value': r''}

    template_in_database = []
    template = {}
    template['delete'] = 'none'
    template['wksht_name'] = 'Sheet1'
    for temp in Template.objects.all():
        t = {}
        t['id'] = temp.id
        t['name'] = temp.temp_name
        template_in_database.append(t)
        if item == int(temp.id):
            template['smtpSver'] = temp.smtp_server
            template['macro'] = temp.marco
            template['subject'] = temp.subject
            template['from'] = temp.sender_mail
            template['logUser'] = temp.login_user
            template['mail_list'] = temp.mail_list
            template['glogin_mail'] = temp.glogin_mail
            template['gFileName'] = temp.gfile_name
            template['wksht_name'] = temp.gwksht_name
            template['id'] = temp.id
            template['delete'] = ''
            fck['value'] = temp.mail_context
            if temp.glogin_mail:
                template['usedgdata'] = 'checked="CHECKED"'
                
    return render_to_response('editmail.html', {'template_in_database': template_in_database,'fck': fck, "template":template})
#end index()

if __name__ == '__main__':
    pass
